Skip to content

feat(project-import): implement asynchronous GitHub repository import into sandbox#142

Merged
Che-Zhu merged 3 commits intomainfrom
codex/import-github-real-import
Mar 10, 2026
Merged

feat(project-import): implement asynchronous GitHub repository import into sandbox#142
Che-Zhu merged 3 commits intomainfrom
codex/import-github-real-import

Conversation

@Che-Zhu
Copy link
Copy Markdown
Collaborator

@Che-Zhu Che-Zhu commented Mar 9, 2026

Background

The Import flow on /projects previously reused the New Project path and only created an empty project. It did not perform a real repository import.
This PR implements the minimum viable end-to-end loop: create project metadata first, then asynchronously import repository code into the sandbox.

Scope

In scope

  • Real GitHub import using GitHub App installation tokens (git clone)
  • Project-level import lifecycle states and error visibility
  • Non-blocking API behavior (importProjectFromGitHub returns immediately)
  • Event-first execution path with polling reconcile as fallback
  • Import dialog integration with status polling and user feedback

Out of scope

  • Automatic skills injection
  • Automatic Claude/Code CLI startup
  • One-click retry button after import failure

Design

Import state machine

  • PENDING: waiting for sandbox readiness
  • CLONING: import in progress
  • READY: import completed
  • FAILED: import failed (project remains usable)

Failure policy matches New Project: do not delete/rollback project on import failure.

Implementation

Data model (prisma/schema.prisma)

  • Added enum ProjectImportStatus: PENDING | CLONING | READY | FAILED
  • Added Project fields:
    • importStatus
    • importError
    • importLockedUntil
    • githubRepoDefaultBranch

Server actions

  • lib/actions/project.ts
    • Extracted shared helper createProjectWithSandbox(...) for both new/import paths
    • Added importProjectFromGitHub(payload):
      • auth and installation ownership validation
      • repository validation
      • project creation with GitHub linkage fields and importStatus=PENDING
  • lib/actions/github.ts
    • Added default_branch in repository metadata returned to UI

Background execution

  • Added lib/jobs/project-import/projectImportReconcile.ts
    • Processes projects in PENDING/CLONING
    • Runs clone when sandbox is RUNNING
    • Updates state to READY on success, FAILED with importError on failure
    • Includes retry behavior and configurable command timeout
  • Added lib/repo/project-import.ts
    • Import-specific lock acquisition and state persistence (aligned with existing optimistic locking style)
  • lib/startup/index.ts
    • Registers and starts/stops the project-import reconcile job

Event-first + polling fallback

  • lib/events/sandbox/sandboxListener.ts
    • Triggers import execution immediately when sandbox transitions to RUNNING
  • Reconcile polling remains as a resilience fallback if event-driven execution is missed

Import command behavior

  • Uses GitHub App installation token; disables interactive git credential prompts
  • Imports into import/<repo>-<projectId>/ (does not overwrite workspace root)
  • Hardened ttyd command dispatch to reduce first-attempt stalls/timeouts

Frontend behavior

  • app/(dashboard)/projects/_components/import-github-dialog.tsx
    • Calls importProjectFromGitHub instead of createProject
    • Polls /api/projects/:id for importStatus
    • READY: success toast + dialog close + list refresh
    • FAILED: fallback toast (“empty project created; import failed”) + close + refresh

Validation

  • Local checks:
    • pnpm lint
    • pnpm build
  • Manual validation:
    • Multiple import runs completed successfully
    • No more reproducible long delay pattern before repository appears

Compatibility and risk

  • New Project behavior remains unchanged in core flow
  • Existing GitHub initialize/push page behavior is preserved
  • Main residual risk is external dependency instability (GitHub/ttyd/K8s), mitigated with explicit import states and persisted error details

@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 9, 2026

✅ PR Check Results: Passed

Build Checks

Check Status
Lint & Build ✅ Passed
Docker Build ✅ Passed

✨ Great work!

All checks passed successfully. Your PR is ready for review.

Details:

  • ✅ Code quality verified (linting passed)
  • ✅ Build successful
  • ✅ Docker image build verified (linux/amd64)
    Commit: 5902b746b38645d1c6c26f35c6081e8ab1f08bf5
    Branch: codex/import-github-real-import

🔗 View Details:

@Che-Zhu Che-Zhu changed the title feat: implement real GitHub import pipeline feat(project-import): implement asynchronous GitHub repository import into sandbox Mar 10, 2026
@Che-Zhu Che-Zhu merged commit beba673 into main Mar 10, 2026
9 checks passed
@Che-Zhu Che-Zhu deleted the codex/import-github-real-import branch March 10, 2026 02:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant